﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace FasterWPF
{
    public static class TextBlockExt
    {
        /// <summary>
        /// Helper method to return the inline run from a TextBlock (since that is what ListBoxExt uses). If no run, returns String.Empty
        /// </summary>
        /// <param name="txb"></param>
        /// <returns></returns>
        public static string GetText(this TextBlock txb)
        {
            string retVal = String.Empty;

            if (txb.Inlines != null && txb.Inlines.Count > 0 && txb.Inlines.FirstInline != null)
            {
                retVal = txb.Inlines.FirstInline.Cast<System.Windows.Documents.Run>().Text.Trim().ToString();
            }

            return retVal;
        }

        public static string SetText(this TextBlock txb, string newText)
        {
            return txb.Inlines.FirstInline.Cast<System.Windows.Documents.Run>().Text = newText;
        }
               
    }//end of class
}//end of namespace
